﻿Public Class DRUGLOCATION

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGLOCATION_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASLOCATIOND()

        DesignForm(Me)
        DesignGrid(MASLOCATIONDGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASLOCATIOND()
        Dim objSelectDataMASLOCATIOND As New maslocationd
        Dim MASLOCATIOND As DataTable
        MASLOCATIOND = connect.GetTable(objSelectDataMASLOCATIOND.selectMaslocationd_)
        MASLOCATIONDGrid.PrimaryGrid.DataSource = MASLOCATIOND
    End Sub

    Private Sub MASLOCATIONDGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASLOCATIONDGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสสถานที่เก็บยา").Value() IsNot DBNull.Value Then
            LOCATIONTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสสถานที่เก็บยา").Value()
        Else
            LOCATIONTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานที่เก็บยา").Value() IsNot DBNull.Value Then
            LOCATENAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานที่เก็บยา").Value()
        Else
            LOCATENAMETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            maslocationdStatusChk.Checked = True
        Else
            maslocationdStatusChk.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE maslocationd SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `location` = '" & LOCATIONTxt.Text & "' ;"

                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addMaslocationd.Enabled = False
    End Sub

    Private Sub addMaslocationd_Click(sender As Object, e As EventArgs) Handles addMaslocationd.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If LOCATENAMETxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New maslocationd
                    objInsertData.LOCATENAME_ = LOCATENAMETxt.Text
                    objInsertData.STATUS_ = maslocationdStatusChk.Checked
                    objInsertData.insertMaslocationdData()

                    SelectDatagridMASLOCATIOND()

                    LOCATIONTxt.Text = ""
                    LOCATENAMETxt.Text = ""
                    maslocationdStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMaslocationd_Click(sender As Object, e As EventArgs) Handles editMaslocationd.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If LOCATIONTxt.Text.ToString.Length > 0 And LOCATENAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลสถานที่เก็บยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New maslocationd
                        objEditData.LOCATION_ = LOCATIONTxt.Text
                        objEditData.LOCATENAME_ = LOCATENAMETxt.Text
                        objEditData.STATUS_ = maslocationdStatusChk.Checked
                        objEditData.editMaslocationdData()

                        SelectDatagridMASLOCATIOND()

                        LOCATIONTxt.Text = ""
                        LOCATENAMETxt.Text = ""
                        maslocationdStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
                addMaslocationd.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExcel.Click
        Dim nextform As New IMPORTEXCEL("maslocationd")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("maslocationd")
        nextform.ShowDialog()
    End Sub
End Class